<template>
  <a-button
    type="default"
    @click="getPhoneCode"
    :loading="loadingCode"
    :disabled="loadingCode"
    class="primary-border-btn"
  >获取验证码</a-button
  >
</template>

<script>
import { getCode } from '@/api/login'
export default {
  props: {
    mobile: {
      type: String,
      default: ''
    },
    codeApi: {
      type: Function,
      default: null
    }
  },
  data () {
    return {
      loadingCode: false
    }
  },
  methods: {
    getPhoneCode () {
      this.loadingCode = true
      const mobile = this.mobile
      const action = this.codeApi || getCode
      action({ mobile })
        .then(res => {
          this.$message.success('发送成功,请注意查收')
        })
        .finally(() => {
          this.loadingCode = false
        })
    }
  }
}
</script>

<style></style>
